home *** CD-ROM | disk | FTP | other *** search
- /*
- *
- * $ FILE : eyes.c
- * $ VERSION : 1
- * $ REVISION : 1
- * $ DATE : 08-Dec-93 18:52
- * $
- * $ Author : mvk
- * $
- *
- *
- * Just EYES.
- *
- *
- */
-
- #include <stdlib.h>
- #include <stdio.h>
-
- #include <exec/types.h>
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <egs/egs.h>
- #include <egs/egsintuigfx.h>
- #include <egs/egsintui.h>
- #include <egs/egslayers.h>
- #include <egs/egsgfx.h>
-
-
- #include <egs/proto/egs.h>
- #include <egs/proto/egsintui.h>
- #include <egs/proto/egslayers.h>
- #include <egs/proto/egsgfx.h>
-
-
- struct EI_NewWindow newWindow =
- {
- 200, 0, 300, 150,
- 300, 150, 300, 150,
- NULL,
- EI_WINDOWCLOSE+EI_WINDOWBACK+EI_WINDOWDRAG,
- NULL, /* GadgetPtr */
- "Eyes",
- EI_SIMPLE_REFRESH,
- EI_iCLOSEWINDOW+EI_iREFRESHWINDOW
- /* Der Rest ist egal */
- };
-
-
-
- EI_WindowPtr win;
- EG_RastPortPtr rast;
- E_EBitMapPtr ras;
- struct EG_AreaInfo info;
- EG_Polygon buffer[40];
- WORD midX, midY;
- WORD radius;
- WORD prad;
- WORD rmax, xmax, ymax;
-
- struct Library *EGSIntuiBase;
- struct Library *EGSLayersBase;
- struct Library *EGSGfxBase;
- struct Library *EGSBase;
-
- void DrawEyes (void)
- {
- rast->APen = win->WinColors.Dark;
- EG_AreaCircle (rast, (WORD)(midX-radius), (WORD)(midY),(WORD)(radius-4));
- EG_AreaCircle (rast, (WORD)(midX+radius), (WORD)(midY), (WORD)(radius-4));
-
- rast->APen = win->WinColors.Light;
-
- EG_AreaCircle(rast, (WORD)(midX-radius), (WORD)(midY),(WORD)(radius-6));
- EG_AreaCircle (rast,(WORD)(midX+radius), (WORD)(midY), (WORD)(radius-6));
- }
-
-
- void DrawPupill (WORD x, WORD y)
- {
- rast->APen = win->WinColors.Dark;
- EG_AreaCircle (rast, (WORD)x, (WORD)y, (WORD)prad);
- rast->APen = win->WinColors.Light;
- EG_AreaCircle (rast, (WORD)(x-prad / 2), (WORD)(y-prad / 2), (WORD)(prad / 4));
-
- }
-
-
- void RedrawPupill (WORD x, WORD y)
- {
- rast->APen = win->WinColors.Light;
- EG_AreaCircle (rast, (WORD)x, (WORD)y, (WORD)prad);
- }
-
-
- WORD py1, py2, px1, px2;
- WORD oy1, oy2, ox1, ox2;
- WORD oldX, oldY;
-
-
- WORD SQR (LONG x)
- {
- WORD h1, h2, h3;
-
- if ((x<0) || (x>2000*2000))
- x = 1;
- h1 = 1;
- h2 = x / 2;
- while ((h1*h1>x) || (h1+1)*(h1+1)<x)
- {
- h3 = (h1+h2) / 2;
- h2 = h1;
- h1 = x / h3; /* oder h3 / x ??? */
- }
- return h1;
- }
-
-
-
- void CalcPupills (WORD dx, WORD dy)
- {
- py1 = midY + ( (dy*(radius-prad-6)) / rmax);
- px1 = midX + ( ((dx+radius)*(radius-prad-6)) / rmax) - radius;
- py2 = midY + ( (dy*(radius-prad-6)) / rmax);
- px2 = midX + ( ((dx-radius)*(radius-prad-6)) / rmax) + radius;
- }
-
-
- void RedrawPupills (void)
- {
- if ((oldX!=win->WScreen->EScreen->MouseX) ||
- (oldY!=win->WScreen->EScreen->MouseY))
- {
- oldX = win->WScreen->EScreen->MouseX;
- oldY = win->WScreen->EScreen->MouseY;
- CalcPupills ((WORD)(oldX-(win->LeftEdge+midX)),(WORD)(oldY-(win->TopEdge+midY)));
-
- EL_LockLayer (win->WLayer);
- E_MouseOff (win->WScreen->EScreen);
- RedrawPupill (ox1, oy1);
- DrawPupill (px1, py1);
- ox1 = px1;
- oy1 = py1;
- RedrawPupill (ox2, oy2);
- DrawPupill (px2, py2);
- ox2 = px2;
- oy2 = py2;
- E_MouseOn (win->WScreen->EScreen);
- EL_UnlockLayer (win->WLayer);
- }
- }
-
-
-
- void ReDraw (void)
- {
- DrawEyes ();
- DrawPupill (px1, py1); ox1 = px1; oy1 = py1;
- DrawPupill (px2, py2); ox2 = px2; oy2 = py2;
- }
-
-
-
- void Crash (char *string)
- {
- if (win!=NULL)
- {
- EI_CloseWindow (win);
- win = NULL;
- }
- if (ras!=NULL)
- E_DisposeBitMap (ras);
- if (EGSIntuiBase)
- CloseLibrary (EGSIntuiBase);
- if (EGSGfxBase)
- CloseLibrary (EGSGfxBase);
- if (EGSLayersBase)
- CloseLibrary (EGSLayersBase);
- if (EGSBase)
- CloseLibrary (EGSBase);
- if (string != NULL)
- {
- printf ("%s\n", string);
- exit (20L);
- }
- exit (0L);
- }
-
-
-
- EI_EIntuiMsgPtr msg;
- BOOL done;
- extern float sqrt (float f);
-
- void main (void)
- {
- /* Öffne die Bibliotheken */
-
- EGSBase = (APTR) OpenLibrary ("egs.library", 0);
- if (NULL == EGSBase)
- Crash ("Konnte EGS.library nicht öffnen");
-
- EGSIntuiBase = (APTR) OpenLibrary ("egsintui.library", 0);
- if (NULL == EGSIntuiBase)
- Crash ("Konnte EGSIntui.library nicht öffnen");
-
- EGSGfxBase = (APTR) OpenLibrary ("egsgfx.library", 0);
- if (NULL == EGSGfxBase)
- Crash ("Konnte EGSGfx.library nicht öffnen");
-
- EGSLayersBase = (APTR) OpenLibrary ("egslayers.library", 0);
- if (NULL == EGSLayersBase)
- Crash ("Konnte EGSLayers.library nicht öffnen");
-
- win = NULL;
- win = EI_OpenWindow (&newWindow);
- if (win == NULL)
- Crash ("Konnte Fenster nicht öffnen");
-
- rast = win->RPort;
- midX = win->BorderLeft + win->Width / 2;
- midY = win->BorderTop + win->Height / 2;
- radius = win->Height / 2;
- prad = (radius*2) / 5;
-
- rmax = (WORD) (sqrt( (float) (( (win->WScreen->Width-radius)*
- (win->WScreen->Width-radius)) +
- ((win->WScreen->Height-radius)*
- (win->WScreen->Height-radius) )) ) );
-
- printf ("Win->Width %d",win->Width);
- printf ("Win->Width %d",win->Height);
-
- ras = E_AllocBitMap (win->Width, win->Height, (UWORD)1, 0, 0,0);
- if (ras == NULL)
- Crash ("Konnte EBitMap nicht belegen");
- else
- {
- rast->TmpRas = ras;
- rast->AreaInfo = EG_InitArea (&info, &buffer[0], (WORD)500);
- oldX = win->WScreen->EScreen->MouseX;
- oldY = win->WScreen->EScreen->MouseY;
- CalcPupills ((WORD)(oldX-(win->LeftEdge+midX)),
- (WORD)(oldY-(win->TopEdge+midY)));
- ReDraw ();
- done = FALSE;
- do {
- Delay (10);
- msg = (EI_EIntuiMsgPtr)GetMsg (win->UserPort);
- while (msg!=NULL)
- {
- if (EI_iREFRESHWINDOW & msg->Class)
- {
- if (EI_BeginRefresh (win, (LONG)msg->IAddress))
- {
- ReDraw ();
- EI_EndRefresh (win, TRUE);
- }
- }
- if (EI_iCLOSEWINDOW & msg->Class)
- done = TRUE;
- ReplyMsg ((struct Message *)msg);
-
- msg = (EI_EIntuiMsgPtr)GetMsg (win->UserPort);
- }
- RedrawPupills ();
- } while (! done);
- }
-
- /* Beende das Programm */
- Crash (NULL);
- }
-
-